package net.xdclass.controller;

import com.alibaba.fastjson.JSON;
import net.xdclass.domain.Video;
import net.xdclass.service.VideoService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/api/v1/video")
public class VideoController {
    @Resource
    private VideoService videoService;
    @Resource
    private HttpServletRequest request;

    @RequestMapping("/find_by_id")
    public Video findById(Integer id){
        Video byId = videoService.findById(id);
        String serviceInfo = request.getRemoteHost() + ":" + request.getRemotePort();
        byId.setServiceInfo(serviceInfo);
        System.out.println(JSON.toJSONString(byId));
        return byId;
    }

    @PostMapping("/save")
    public Video save(@RequestBody Video param){
        String serviceInfo = request.getRemoteHost() + ":" + request.getRemotePort();
        param.setServiceInfo(serviceInfo);
        System.out.println(JSON.toJSONString(param));
        return param;
    }
}
